﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using RabbitMQ.Client;
using System.Text;

namespace Xms.MQ
{
    public class RabbitMQSend
    {
        static RabbitMQFactory connection = null;
        const string exchangeName = "lim_message.exchange";
        static RabbitMQSend()
        {
            connection = new RabbitMQFactory();
        }
        public static void PushMessage(string queueName,string msgdata)
        {
            using (var channel = connection.CreateModel())
            {

                channel.ExchangeDeclare(exchangeName, "topic", durable: false, autoDelete: false, arguments: null);
                channel.QueueDeclare(queueName, durable: false, autoDelete: false, exclusive: false, arguments: null);//durable持久化 MQ重启是否存在
                channel.QueueBind(queueName, exchangeName, routingKey: queueName);
                var msgBody = Encoding.UTF8.GetBytes(msgdata);
                channel.BasicPublish(exchange: exchangeName, routingKey: queueName, basicProperties: null, body: msgBody);
            }
        }
    }
}
